package entity.Card;

import javax.swing.*;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Vector;

import javax.swing.JRadioButton;


public class MCcard extends EventCard implements ActionListener{
	private static Vector<Card> allMC = new Vector<Card>();
	private int[] markList = new int[4];
	private String[] choice = new String[4];

	
	public MCcard(String content,String[] choice,int effect[], boolean isChinese) {
		super("Mutliple Choice","mc",content,effect[0],isChinese);
		this.choice=choice;
		this.markList=effect;
		allMC.add(this);
	}
	public MCcard() {
	}

	public int display(){
		if(!isChinese){
			return showPopup(typeEng,this.content,this.choice[0],this.choice[1],this.choice[2],this.choice[3]);
		}
		else{
			return showPopup(typeChi,this.content,this.choice[0],this.choice[1],this.choice[2],this.choice[3]);
		}
	}
	public int showPopup(String type,String question, String choiceA, String choiceB, String choiceC, String choiceD){
		JRadioButton rb1 = new JRadioButton(choiceA);
		rb1.setActionCommand("A");
	    JRadioButton rb2 = new JRadioButton(choiceB);
	    rb2.setActionCommand("B");
	    JRadioButton rb3 = new JRadioButton(choiceC);
	    rb3.setActionCommand("C");
	    JRadioButton rb4 = new JRadioButton(choiceD);
	    rb4.setActionCommand("D");
	    ButtonGroup group = new ButtonGroup();
        group.add(rb1);
        group.add(rb2);
        group.add(rb3);
        group.add(rb4);
        rb1.addActionListener(this);
        rb2.addActionListener(this);
        rb3.addActionListener(this);
        rb4.addActionListener(this);
        
        Object[] message = {type,question,rb1,rb2,rb3,rb4};


		JOptionPane pane= new NarrowOptionPane();
		pane.setMessage(message);
		pane.setMessageType(JOptionPane.QUESTION_MESSAGE);
	    
		JDialog getTopicDialog =  pane.createDialog(null, type);
	    getTopicDialog.setVisible(true);
		getTopicDialog.setResizable(false);
		return choiceEffect;
	}
	public void actionPerformed(ActionEvent e) {
		if(e.getActionCommand() == "A"){
			choiceEffect=this.markList[0];
		}
		else if(e.getActionCommand() == "B")
			choiceEffect=this.markList[1];
		else if(e.getActionCommand() == "C")
			choiceEffect=this.markList[2];
		else
			choiceEffect=this.markList[3];
	}
	public int getCardTotal(){
		return allMC.size();
	}
	
	public Vector<Card> getAllCard(){
		return allMC;
	}
	public int[] getMarkList(){
		return this.markList;
	}
	
	public String[] getChoiceList(){
		return this.choice;
	}
}